﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using Autofac;
using Com.ArHat.BLL;
using Com.ArHat.IBLL;
using Com.ArHat.Model.Models;
using Com.ArHat.Test.Common;

namespace Com.ArHat.Test
{
    class Program
    {
        static void Main(string[] args)
        {
           Program p=new Program();
           p.LinqTest();
            // p.EFProduce();
            //   p.EFConnect();
        }

        public void EFConnect()
        {
            IQueryable<User> users;
            IQueryable<Menu> menus;
            users = IocContainer.IOContainer.Container.Resolve<IUserServices>().GetUserList();
            menus = IocContainer.IOContainer.Container.Resolve<IMenuService>().GetMenusList();
            foreach (var menu in menus)
            {
                Console.WriteLine(menu.Name);
            }
            foreach (var user in users)
            {
                Console.WriteLine(user.UserName);
            }
            Console.Read();
        }


        public void ADOConnect()
        {
            string cstr = "server=.;Initial Catalog=master;Integrated Security=SSPI";
            //  
            try
            {
                using (SqlConnection con = new SqlConnection(cstr))
                {
                    con.Open();
                    System.Console.WriteLine("ServerVersion:{0}", con.ServerVersion);
                    System.Console.WriteLine("State:{0}", con.State);
                }

            }
            catch (System.Exception sqle)
            {
                System.Console.WriteLine(sqle.Message);
            }
            Console.Read();
        }

        public void EFProduce()
        {
            List<string> strList = CommonService.GetMenuName().ToList();
            foreach (string s in strList)
            {
                Console.WriteLine(s);
            }
            Console.Read();
        }


        public void luoxuan()
        {
            var rd = new Random();  
  
            int r = rd.Next(10);  
            int n = r + 1;  
            int j = 0;  
            int[,] rec = new int[10,10];  
            Console.WriteLine("生成的随机数是：" + r);  
            while (j <= r/2)  
            {  
                //第一次输出最左边的数字  
                for (int i = j; i <= r - j; i++)  
                {  
                    if (j == 0)  
                    {  
                        rec[i,j] = i + 1;  
                    }  
                    else  
                    {  
                        rec[i,j] = rec[i - 1,j] + 1;  
                    }  
                }  
                //第二次输出最下边的数字  
                for (int i = j + 1; i <= r - j; i++)  
                {  
                    rec[r - j,i] = rec[r - j,i - 1] + 1;  
                }  
                //第三次输出最右边的数字  
                for (int i = r - j - 1; i >= j; i--)  
                {  
                    rec[i,r - j] = rec[i + 1,r - j] + 1;  
                }  
  
                for (int i = r - j; i > j + 1; i--)  
                {  
                    rec[j,i - 1] = rec[j,i] + 1;  
                }  
                j++;  
            }  
  
  
            for (int i = 0; i < n; i++)  
            {  
                for (int k = 0; k < n; k++)  
                {  
                   Console.Write(rec[i,k] + " ");  
                }  
                Console.WriteLine("");  
            }  
            Console.Read();  
        }

        public void LinqTest()
        {
            List<int> list=new List<int>()
            {
                0,1,2,3,4,5,6,7,8,9
            };
            var temp = from i in list where i > 5 select i ;
            var temp2 = (from i in list where i > 5 select i).ToList<int>();
            list[0] = 11;
            Console.Write("temp查询：");
            foreach (int i in temp)
            {
                
                Console.Write(i+"\t");
            }
            Console.WriteLine();
            Console.Write("temp2查询：");
            foreach (int i in temp2)
            {

                Console.Write(i + "\t");
            }
            Console.Read();
        }
        }
    }


